<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of propierties_controller
 *
 * @author 250-1-405
 */
class TechnicalVisitsController extends AppController {

    var $name = "TechnicalVisits";

    public function index($property_id) {
        $this->paginate = array('TechnicalVisits' => array('recursive' => -1, 'maxLimit' => 500, 'limit' => 50, 'fields' => array('TechnicalVisit.id', 'TechnicalVisit.fecha', 'TechnicalVisit.comentario')));
        $this->set('TechnicalVisits', $this->paginate(array('TechnicalVisit.property_id' => $property_id)));
        $this->set('property_id', $property_id);
    }

    public function add($property_id) {
        $this->layout = "ajax";
        $this->set('property_id', $property_id);
        if (!empty($this->data)) {
            if ($this->TechnicalVisit->save($this->data)) {
                $this->Session->setFlash('Registro Adicionado correctamente', 'flash_custom');
                $this->redirect(array('controller' => 'TechnicalVisits', 'action' => 'index', $property_id));
            } else {
                //ERROR GUARDANDO DATOS
                $this->Session->setFlash('Error Guardando datos');
                $this->redirect(array('controller' => 'TechnicalVisits', 'action' => 'index', $property_id));
            }
        } else {
            
        }
    }

    public function edit($id) {
        if (empty($this->data)) {
            $this->data = $this->TechnicalVisit->find('first', array('conditions' => array('TechnicalVisit.id' => $id), 'fields' => array('TechnicalVisit.*')));
        } else {
            if ($this->TechnicalVisit->save($this->data)) {
                $this->Session->setFlash('Registro editado correctamente', 'flash_custom');
                $this->redirect(array('controller' => 'TechnicalVisits', 'action' => 'index', $this->data['TechnicalVisit']['property_id']));
            } else {
                $this->Session->setFlash('Error editando datos');
                $this->redirect(array('controller' => 'TechnicalVisits', 'action' => 'index', $this->data['TechnicalVisit']['property_id']));
            }
        }
    }

    public function delete($id, $property_id) {
        if ($this->TechnicalVisit->delete($id)) {
            $this->Session->setFlash('Registro borrado correctamente', 'flash_custom');
            $this->redirect(array('controller' => 'TechnicalVisits', 'action' => 'index', $property_id));
        }
    }

}

?>